<?php
function FormatHeader(){
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>


<title>W-Programming Online Judge (WPOJ)</title>
<link href="Images/style.css" rel="stylesheet" type="text/css" id="theme">
<style type="text/css">
<!--
.maintable {width: 755px;} 
-->
</style>

</head><body>
<center>
<table class="maintable" id="maintable" cellpadding="10" cellspacing="0">
<tbody><tr>
    <td colspan="2" class="header">
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tbody><tr>
		<td class="headercenter">
			<h1><img alt="W-Programming Online Judge" title="W-Programming Online Judge" src="Images/wpoj.png" style="margin-top: -4px; margin-bottom: -4px;" border="0"></h1>
	</td></tr>
	</tbody></table>
    </td>
</tr>
<tr>
<td class="menu" valign="top" width="92">
<div class="menucmd">

';}

function echo_unreg(){
	echo'
		<a href="/login.php">login</a><br>
		<a href="/register.php">register</a><br><br>
	';
}
function encrypt($arg)
{
	$poz=0;
	for ($i = 0; $arg[$i]; ++$i){
		$a = ord($arg[$i]);
		$b = ord('a');
		$c = $a - $b;
		if ($c < 10){
			$encr[$poz]=$c;
			$poz++;
		}
		else{
			$encr[$poz]=$c % 10;
			$poz++;
			$encr[$poz]=floor($c / 10);
			$poz++;
		}
	}
		//$arg[$i]+=$i;
	for ($i = 0; $i < $poz; ++$i){
		$ret[$i] = chr(ord('0') + $encr[$i]);
	//	echo '('.$encr[$i]." ".$ret[$i].') ';
	}
	//echo ' ';
	$ret[$poz] = 0;
	return implode("",$ret);
}
function no_user(&$username){
	echo '<h1> Username does not exist </h1>';
	echo_log();
	$username=false;
	return false;
}
function FormatLeft (){
$WPOJ_Is_Logged = 0;
if ($_COOKIE["user"] && $_COOKIE["password"]){
	mysql_connect("localhost", "root", "apache") or die(mysql_error());
	mysql_select_db("jobs") or die(mysql_error());
	$username=true;
	//echo $_COOKIE["user"].$_COOKIE["password"];
	//echo "SELECT * FROM users where user = '".$_COOKIE["user"]."'";
	$result = mysql_query("SELECT * FROM users where user = '".$_COOKIE["user"]."'") or die(mysql_error()); 
	$row = mysql_fetch_array( $result ) or no_user($username);
	if ($username == true){
		if ($_COOKIE["password"]){
			$encryptpass = $_COOKIE["password"];
			if ($encryptpass == $row['password']){
				echo '<a href="/logout.php">Log Out</a><br>';
				echo $row['user'].'<br><hr>';
				$WPOJ_Is_Logged = 1;
				$WPOJ_User = $row['user'];
				$WPOJ_Rank = $row['rights'];
				if ($row['rights'] > 0){
					if ($row['rights'] == 2){
						// pun ce apare la admini
						# forum admin
						echo '<a href="/reeval.php">reevaluate submissions</a><br>';
						echo '<a href="/forum/adm">forum admin</a><br>';
						echo '<a href="/addcontest.php">add contest</a><br><hr>';
					}
					echo '<a href="/addproblem.php">add problem</a><br>';
					echo '<a href="/uploadfiles.php">upload files</a><br>';
					echo '<a href="/myproblemlist.php">problem list</a><br><hr>';					
					// pun ce apare la admini + helperi
				}
				echo '<a href="/myaccount.php">my account</a><br>';
				// pun ce apare la toti
				echo '<br>';
			}
			else
				echo_unreg();
		}
		else
			echo_unreg();
	}
	else
		echo_unreg();
}
else
	echo_unreg();
echo '
	<a href="/status.php">status</a><br>
	<a href="/submit.php">submit</a><br>
	<a href="/problems.php">problems</a><br><br>
	<a href="/">news</a><br>
	<a href="/contests.php">contests</a><br>
	<a href="/ranks.php">ranks</a><br><br>
	<a href="/forum">forum</a><br>
	<a href="/help.php">help</a><br><hr></div><div class="time">
Server time:
</div>
<div class="time">';
echo date("Y-m-d");
echo '<br><b>';
echo date("H : m : s");
echo '</b>
</div>
</td><td class="content" width="99%">
<p align="justify">';
}
// put news here or smth

function FormatFooter(){
echo'
</p></td>
</tr>

<tr>
<td colspan="2" class="footer">

<script language="javascript" type="text/javascript">
<!--
function swapSheet(sheet, caller) {
    document.getElementById(\'theme\').href=sheet;
    document.cookie="css_0="+sheet+"; path=/;";
    caller.href="#bottom";
}

function setWidth(w, caller) {
    document.getElementById(\'maintable\').style.width=w;
    document.cookie="res="+w+"; path=/;";
    caller.href="#bottom";
}


</script>
        <table width="100%">
    <tbody><tr>
	<td class="cfooter" align="left" width="10%">
		<a href="/info.php">About WPOJ</a>
	</td>
	<td class="cfooter" align="center">
	    page size:
	    <a href="/?rsl=755px" onclick="setWidth(\'755px\', this)">800x600</a>
	    <a href="/?rsl=980px" onclick="setWidth(\'980px\', this)">1024x768</a>
	    <a href="/?rsl=100%" onclick="setWidth(\'100%\', this)">Full</a>
	    &nbsp;&nbsp;
	</td>
    </tr>
    </tbody></table>
    </td></tr></tbody></table>
</center>
<div style="font-size: 10px; margin-top: 4px; color: rgb(85, 80, 95);"><center>
<a href="http://www.wpoj.ro/" style="color: black;">WPOJ</a>
System &#169; 2008-2009
<a href="toni" style="color: black;">Toni Pripoae</a>.  All Rights Reserved.</center></div>

</body></html>';
}
?>
